<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->model("cat_model");
    }
    
    public function index(){
        $this->makeDataForFirstPage($data);  
        $this->load->view('welcome_message', $data);
    }
    
    
    private function makeDataForFirstPage(&$data) {
        $query = $this->cat_model->getFirstPageData();
        $data['query'] = $query;
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                if ($row->prd_count > 0) {
                    $sum["cat" . $row->CAT_ID] = $row->prd_count . " รายการ";
                } else {
                    $sum["cat" . $row->CAT_ID] = "ยังไม่มีรายการสินค้า";
                }
            }
        }
        
        $data['sum'] = $sum;
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */